﻿using BackData;
using Domain.DTOs.Equipmentes;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Team.API.Applocation.Command.Equipment;

namespace Team.API.Controllers
{
    /// <summary>
    /// 设备管理控制器
    /// <para>提供设备创建、查询、修改、删除等接口</para>
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EquipmentController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数，注入中介者组件
        /// </summary>
        /// <param name="mediator">MediatR 中介者组件，用于分发命令和查询</param>
        public EquipmentController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 创建设备接口
        /// </summary>
        /// <param name="request">创建设备的命令对象，包含设备创建所需的信息</param>
        /// <returns>包含设备ID的API结果</returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateEquipment(CreateEquipmentCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 用于查询设备列表
        /// </summary>
        /// <param name="request">查询设备列表的命令对象</param>
        /// <returns>包含EquipmentDTO列表的APIResult</returns>
        [HttpGet]
        public async Task<APIResult<List<EquipmentDTO>>> GetEquipmentList([FromQuery]GetEquipmentListCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 处理设备更新请求的接口
        /// </summary>
        /// <param name="request">设备更新命令，包含待更新设备的信息</param>
        /// <returns>异步返回包含更新结果、状态码和提示信息的APIResult</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateEquipment(UpdateEquipmentCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 处理设备删除请求的接口
        /// </summary>
        /// <param name="request">设备删除命令，包含待删除设备的ID</param>
        /// <returns>异步返回包含删除结果、状态码和提示信息的APIResult</returns>
        [HttpPut]
        public async Task<APIResult<int>> DeleteEquipment(DeleteEquipmentCommand request)
        {
            return await mediator.Send(request);
        }

         
    }
}
